package 字符串.easy;

/**
 * LWZ TODO : 2020/8/19
 * 不明题意
 */

/**
 * @author Lw中
 * @date 2020/8/19 11:59
 */
public class SanBa {

    public static String countAndSay(int n) {
        String s = "";
        int p1 = 0;
        int cur = 1;
        if ( n == 1 ) {
            return "1";
        }
        String str = countAndSay(n - 1);
        for ( cur = 1; cur < str.length(); cur++ ) {
            if ( str.charAt(p1) != str.charAt(cur) ) {
                int count = cur - p1;
                s = s + count + ""+str.charAt(p1);
                p1 = cur;
            }
        }
        if ( p1 != cur ){
            int count = cur - p1;
            s = s + count +""+ str.charAt(p1);
        }
        return s;
    }

    public static void main(String[] args) {
        String s = countAndSay(3);
        System.out.println(s);
    }

}
